package com.corpgovernment.travelstandard.enums;

import com.corpgovernment.travelstandard.entity.db.MbTravelstandCarModel;
import com.corpgovernment.travelstandard.vo.NodeVO;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jhxue
 * @create 2022-05-12-18:10
 */
@Getter
public enum TrainTransferCarModelEnum {

	/**
	 * 经济型
	 */
	ECONOMICAL("经济型", "economical"),
	/**
	 * 舒适型
	 */
	COMFORT("舒适型", "comfort"),
	/**
	 * 商务型
	 */
	BUSINESS("商务型", "business"),
	/**
	 * 豪华型
	 */
	LUXURY("豪华型", "luxury"),
	/**
	 * 出租车
	 */
	BUS("巴士", "bus"),
	/**
	 * 其它
	 */
	OTHER("其它", "other");

	private String code;

	private String name;

	TrainTransferCarModelEnum(String name, String code) {
		this.name = name;
		this.code = code;
	}

	/**
	 * 传入已选中的code，转为node列表
	 *
	 * @return
	 */
	public static List<NodeVO> getCheckedNodeByCode(List<MbTravelstandCarModel> travelstandCarModels) {
		int count = 0;
		List<NodeVO> nodes = new ArrayList<>();
		if (CollectionUtils.isEmpty(travelstandCarModels)) {
			travelstandCarModels = new ArrayList<>();
		}
		for (TrainTransferCarModelEnum transferCarModelEnum : TrainTransferCarModelEnum.values()) {
			NodeVO node = new NodeVO();
			node.setId(String.valueOf(count));
			node.setCode(transferCarModelEnum.getCode());
			node.setName(transferCarModelEnum.getName());
			node.setIsChecked(false);
			for (MbTravelstandCarModel standardCarModel : travelstandCarModels) {
				if (transferCarModelEnum.getCode().equals(standardCarModel.getModelCode())) {
					node.setIsChecked(true);
				}
			}
			nodes.add(node);
			count++;
		}
		return nodes;
	}
}
